package com.terrier.iso
{
    import flash.geom.Point;

    public class IsoObject
    {
        protected var _x:Number;

        protected var _y:Number;

        protected var _z:Number;

        protected var _needUpdatePos:Boolean;

        public var screenX:Number;

        public var screenY:Number;

        public var depth:Number;

        public function IsoObject()
        {

        }

        public function get x():Number
        {
            return _x;
        }

        public function set x(value:Number):void
        {
            _x = value;
            _needUpdatePos = true;
        }

        public function get y():Number
        {
            return _y;
        }

        public function set y(value:Number):void
        {
            _y = value;
            _needUpdatePos = true;
        }

        public function get z():Number
        {
            return _z;
        }

        public function set z(value:Number):void
        {
            _z = value;
            _needUpdatePos = true;
        }

        public function updatePosition():void
        {
            if (_needUpdatePos)
            {
				isoToScreen();
            }
        }
		
		public function onRemoved():void
		{
			
		}
		
		public function onAdded():void
		{
			
		}
		
		public function update(elapseTime:Number):void
		{
			updatePosition();
		}
		
		public function render():void
		{
			
		}

        public function isoToScreen():void
        {
            screenX = _x - _y;
            screenY = (-_z) * IsoUtility.COS_THETA_MINUS_MULTIPLY_SQRT2 + (_x + _y) * IsoUtility.SIN_THETA;
            depth = (_x + _y) * IsoUtility.COS_THETA_MINUS - (-_z) * IsoUtility.SIN_THETA_MULTIPLY_SQRT2;
        }

        public function screenToIso():void
        {
            _x = screenY * IsoUtility.RECIPROCAL_SIN_THETA_HALF + screenX * 0.5;
            _y = screenY * IsoUtility.RECIPROCAL_SIN_THETA_HALF - screenX * 0.5;
            _z = 0;
        }
    }
}
